package sctu.edu.java.year2016.team01.xuhanmei.day20160605.chapter12_3;

import javax.swing.*;
import java.awt.*;
import java.awt.event.InputMethodEvent;
import java.io.*;

/**
 * Created by Administrator on 2016/6/5.
 * 实现当用户输入姓名和密码时，将每一个姓名和密码加在文件中。。
 * 未完成！！
 */
public class NameandPassword extends JFrame {
    public static void main(String[] args) throws Exception {
        JFrame jl = new JFrame("姓名和密码的录入");
        jl.setSize(500, 500);
        jl.setVisible(true);
        jl.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }


    private void kinbuttonActionPerformed(java.awt.event.ActionEvent evt) {
        File file = new File("d:/java小程序/12_3.text");
        try {
            InputMethodEvent nametextField = null;
            InputMethodEvent passwordtextField = null;
            if (nametextField.getText().equals("") || passwordtextField.getText().equals("")) {
                JOptionPane.showMessageDialog(this, "请输入完整的名字和密码", "信息提示框", JOptionPane.WARNING_MESSAGE);
                return;
            }

            if(!file.exists())
                file.createNewFile();
                BufferedWriter out=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,true)));
            Object nameTextField =null;
            out.write("姓名"+ passwordtextField.getText() +",  ");
            out.write("密码"+passwordtextField.getText());
            out.newLine();
            out.close();

        } catch (FileNotFoundException e1) {
            e1.printStackTrace();
        } catch (IOException e1) {
            e1.printStackTrace();
        }

    }
        }


